<?php

use yii\helpers\Html;
use yii\widgets\ActiveForm;

/* @var $this yii\web\View */
/* @var $model common\models\customInfo\CustomInfo */
/* @var $form yii\widgets\ActiveForm */
?>
<?php $this->beginBlock('siderbar'); ?>
<?= $this->render('//layouts/act-menu') ?>
<?php $this->endBlock(); ?>
<div class="custom-info-form">

    <?php $form = ActiveForm::begin(); ?>
    <div class="form-group field-custominfo-code has-success">
        <?php 
        if(!empty($model->sub_info))
        {
        foreach (unserialize($model->sub_info) as $key => $value) { 
            //如果是多选框
            if($value['type']=="checkbox")
            {?>
            <label class="control-label" for="custominfo-code"><?= $value['name'];?></label><br/>
             <?php  
               $activity = Yii::$app->db->createCommand('SELECT cu_id FROM activity where ac_id='.$model->ac_id)->queryOne();
               $arr = explode(',', $value['value']);
               $evalue = Yii::$app->db->createCommand("SELECT evalue FROM custom_elements where set_id=" .$activity['cu_id']." and name='id_checkbox'")->queryOne();
                foreach (unserialize($evalue['evalue']) as $key => $val) { ?>
                    <input id="custominfo-code"  name="<?= $value['type'];?>[]" <?php if(in_array($val['name'], $arr)){ ?> checked="checked"  <?php } ?> value="<?= $val['name'];?>" type="checkbox">
                    <?= $val['name'];?>
                    <div class="help-block"></div>
               <?php  }
            }
            //如果是下来菜单
            elseif($value['type']=="dropdown")
            { ?>
                <label class="control-label" for="custominfo-code"><?= $value['name'];?></label><br/>
                <select name="<?= $value['type'];?>">
                    <?php 
                    //循环输出所有下来选项
                    $all = Yii::$app->db->createCommand("SELECT evalue FROM custom_elements where set_id=" .$activity['cu_id']." and name='id_dropdown'")->queryOne();
                    foreach (unserialize($all['evalue']) as $key => $suoyou) { ?>
                        <option  name="<?= $value['type'];?>" <?php if($value['value']==$suoyou['name']){ ?> selected="selected" <?php } ?> value="<?= $suoyou['name']?>"><?= $suoyou['name']?></option>
                    <?php } ?> 
                </select>
                <div class="help-block"></div>
            <?php 
            }
            //如果是单选按钮
            elseif($value['type']=="radio")
            {?>
                <label class="control-label" for="custominfo-code"><?= $value['name'];?></label><br/>
               <?php 
               //查询所有单选框值
                $all = Yii::$app->db->createCommand("SELECT evalue FROM custom_elements where set_id=" .$activity['cu_id']." and name='id_radio'")->queryOne();
                foreach (unserialize($all['evalue']) as $key => $suoyou) { ?>
                <label><input name="<?= $value['type'];?>" <?php if($value['value']==$suoyou['name']){ ?> checked="checked" <?php } ?> value="<?= $suoyou['name']?>" type="radio"><span class="optionValue"><?= $suoyou['name']?></span></label>
                <div class="help-block"></div>
                <?php } ?>
            <?php 
            }
            else
            { ?>
             <label class="control-label" for="custominfo-code"><?= $value['name'];?></label>
             <input id="custominfo-code" class="form-control" name="<?= $value['type'];?>" value="<?= $value['value'];?>" type="text">
           <?php  } }  } ?>
    <div class="help-block"></div>
    </div>

    <!-- <?= $form->field($model, 'token')->textInput(['maxlength' => true]) ?> -->

    <!-- <?= $form->field($model, 'wecha_id')->textInput(['maxlength' => true]) ?> -->

    <?= $form->field($model, 'ac_id')->textInput() ?>

    <?= $form->field($model, 'add_time')->textInput(['maxlength' => true]) ?>

    <!-- <?= $form->field($model, 'user_name')->textInput(['maxlength' => true]) ?> -->

    <!-- <?= $form->field($model, 'phone')->textInput(['maxlength' => true]) ?> -->

    <!-- <?= $form->field($model, 'sub_info')->textarea(['rows' => 6]) ?> -->

    <?= $form->field($model, 'status')->textInput() ?>

    <?= $form->field($model, 'code')->textInput(['maxlength' => true]) ?>

    <div class="form-group">
        <?= Html::submitButton($model->isNewRecord ? Yii::t('app', 'Create') : Yii::t('app', 'Update'), ['class' => $model->isNewRecord ? 'btn btn-success' : 'btn btn-primary']) ?>
    </div>

    <?php ActiveForm::end(); ?>

</div>
